package evs1.restframework.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import evs1.restframework.HibernateConnector;
import evs1.restframework.model.Company;
import evs1.restframework.model.Occupation;
import evs1.restframework.model.Person;
import evs1.restframework.model.Skill; 

public class HibernateTest 
{
	private HibernateConnector hc;
	
	public HibernateTest() throws ParseException
	{
		Person p = new Person();
		p.setPrename("Prename");
		p.setSurname("asdgasdgasdg");
		p.setDescription("The description");
		
		Skill s = new Skill();
		s.setName("English");
		s.setPerson(p);
		
		Skill s1 = new Skill();
		s1.setName("German");
		s1.setPerson(p);
		
		HashSet<Skill> skills = new HashSet<Skill>();
		skills.add(s);
		skills.add(s1);
		
		p.setSkills(skills);
				
		
				
		
		SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
		Company c = new Company();
		c.setName("google");
		c.setFounded(sdf.parse("10.12.2000"));
		c.setFieldOfActivity("computing");
		
		s = new Skill();
		s.setName("English");
		s.setCompany(c);
		
		s1 = new Skill();
		s1.setName("German");
		s1.setCompany(c);
		
		skills = new HashSet<Skill>();
		skills.add(s);
		skills.add(s1);
		
		c.setSkills(skills);
		
		Occupation o = new Occupation();
		try {
			o.setBegin(sdf.parse("10.12.2005"));
			o.setEnd(sdf.parse("12.11.2009"));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		o.setPosition("CEO");
		o.setCompany(c);
		o.setPerson(p);
		
		HashSet<Occupation> occupations = new HashSet<Occupation>();
		occupations.add(o);
		p.setOccupations(occupations);
		c.setOccupations(occupations);
		
		hc = new HibernateConnector();		
		hc.postToHibernate(p);
		hc.postToHibernate(c);		
				
		System.out.println(((Person) hc.getFromHibernate(Person.class, 1)).toString());
		System.out.println(((Company) hc.getFromHibernate(Company.class, 1)).toString());
	}
	
	public static void main(String[] args) throws ParseException
	{
		new HibernateTest();
	}
}
